.TH std::istrstream::istrstream 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::istrstream::istrstream \- std::istrstream::istrstream

.SH Synopsis
   explicit istrstream( const char* s );           \fB(1)\fP (deprecated in C++98)
                                                       (removed in C++26)
   explicit istrstream( char* s );                 \fB(2)\fP (deprecated in C++98)
                                                       (removed in C++26)
   istrstream( const char* s, std::streamsize n ); \fB(3)\fP (deprecated in C++98)
                                                       (removed in C++26)
   istrstream( char* s, std::streamsize n );       \fB(4)\fP (deprecated in C++98)
                                                       (removed in C++26)

   Constructs new std::istrstream and its underlying std::strstreambuf.

   1,2) Constructs the underlying std::strstreambuf by calling strstreambuf(s, 0) and
   initializes the base class with the address of the strstreambuf. The behavior is
   undefined if s is not pointing at an element of a null-terminated array.
   3,4) Constructs the underlying std::strstreambuf by calling strstreambuf(s, n) and
   initializes the base class with the address of the strstreambuf. The behavior is
   undefined if s is not pointing at an element of an array whose length is at least n
   elements.

.SH Parameters

   s - C-string or char array to use as the contents of the stream
   n - size of the array

.SH Example


// Run this code

 #include <iostream>
 #include <strstream>

 int main()
 {
     std::istrstream s1("1 2 3"); // string literal
     int n1, n2, n3;
     if (s1 >> n1 >> n2 >> n3)
         std::cout << n1 << ", " << n2 << ", " << n3 << '\\n';

     char arr[] = {'4', ' ', '5', ' ', '6'};
     std::istrstream s2(arr, sizeof arr);
     if (s2 >> n1 >> n2 >> n3)
         std::cout << n1 << ", " << n2 << ", " << n3 << '\\n';
 }

.SH Output:

 1, 2, 3
 4, 5, 6

.SH See also

   constructor   constructs a strstreambuf object
                 \fI(public member function of std::strstreambuf)\fP
   constructor   constructs an ostrstream object, optionally allocating the buffer
                 \fI(public member function of std::ostrstream)\fP
   constructor   constructs a strstream object, optionally allocating the buffer
                 \fI(public member function of std::strstream)\fP
